﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _3._1
{
    class Delta:shape
    {
        private double a;
        private double b;
        private double c;

        public Delta(double a, double b, double c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
            if (!this.check())
            {
                Console.WriteLine("三角形不合法,取默认，abc为2");
                this.a = 2;
                this.b = 2;
                this.c = 2;
            }
        }

        public override string ToString()
        {
            double s = this.area();
            return "这是一个三角形,三边长：" + a.ToString("f3") + " "+b.ToString("f3") + " "+c.ToString("f3") + ",面积：" + s.ToString("f3")+"\n";
        }

        public override double area()
        {
            double p = (a + b + c) / 2;
            return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
        }

        public override bool check()
        {
            if (a>0&&b>0&&c>0&&a+b>c&& Math.Abs(a - b)<c)
            {
                
                return true;
            }
            return false;
        }
    }
}

